/****************************************************
 * 创建人：  tanglei  
 * 创建时间: 2022/3/12/14:42
 * 项目名称：junit_test
 * 文件名称: JoinTester01.java
 * 文件描述: @Description: 
 *
 * All rights Reserved, Designed By 投资交易团队
 * @Copyright:2016-2022
 *
 ********************************************************/
package com.springboot.thread;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * 包名称：  src.multiThread
 * 类名称：JoinTester01
 * 类描述：
 * 创建人：  tanglei
 * 创建时间：2022/3/12 14:42
 */

public class JoinTester01 implements Runnable {
    private String name;

    public JoinTester01(String name) {
        this.name = name;
    }

    public void run() {
        System.out.printf("%s begins: %s\n", name, new Date());
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.printf("%s has finished: %s\n", name, new Date());
    }

    public static void main(String[] args) {
        Thread thread1 = new Thread(new JoinTester01("One"));
        Thread thread2 = new Thread(new JoinTester01("Two"));
        thread1.start();
        thread2.start();

        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("Main thread is finished");
    }
}

